@extends('layouts.back_stage')
@section('content')
  <style>
  #app{padding:20px}
  [v-cloak] {display: none;}
  .getadd{display:inline-block;background:#409eff;height:30px;width:50px;
    text-align:center;line-height:35px;color:#fff;font-size:16px;margin-left:20px;
    border-radius:8%}
  .ingred_sel{width:200px;margin:0 30px 0 10px}
  .table_margin{padding:30px;background:#fff;text-align:center;margin-top:10px}
  table{text-align:center}
  .pation{text-align:center}
  .updata{font-size:10px;color:#409eff}
  .add_look{width:250px; margin:0 30px 0 10px}
  .look_margin{margin:10px 0}
  .look_width{width:250px;}
  .look_tab{width:80px;}
  .span{border:1px solid #dadde3;background:#f5f7fa;display:inline-block;width:180px;height:30px;line-height:30px;padding-left:5px;color:#dadde3}
  .tab_width{width:110px}
  .caser{width:250px}
  ::-webkit-scrollbar {height: 8px;}
  .el-table .warning-row {background: #ccc;}
  .el-table .success-row {background: #92cc17;}
  .spTip{width:20px;height:20px;display:inline-block;margin:0 5px 0 20px;}
  .shopBg{background:#fff;overflow: hidden;padding:29px 0 28px 25px;margin-top:15px;}
  .touching{float:right;margin-right:30px;}
  .el-button+.el-button.picking{float:right;margin-right:15px;margin-left:0;}
  .pagination-box{text-align: center;box-sizing:border-box;margin-top:20px;}
  .el-table tr:hover>td{background:initial !important;}
  .el-table tr.current-row>td{background:initial !important;}
  .el-table__expanded-cell[class*=cell]{padding:0 !important;}
  .el-table--striped .el-table__body tr.el-table__row--striped.current-row td, .el-table__body tr.current-row>td, .el-table__body tr.hover-row.current-row>td, .el-table__body tr.hover-row.el-table__row--striped.current-row>td, .el-table__body tr.hover-row.el-table__row--striped>td, .el-table__body tr.hover-row>td{background:initial !important;}
  .el-upload__input{opacity:0}
  .gif_margin{margin:10px 0 10px 80px}
  .v-modal{z-index: 2000}
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
  </style>
  <div class="container">
      <div style="padding:20px 20px 10px 0;overflow:hidden;"><h3 style="float:left;">分支机构管理</h3></div>
            <div class="page-body">
                <div class="row app" id="app"  v-cloak>
                    <el-button type="primary" class="touching" size="small" @click="expost">导出</el-button>
                    <el-button type="primary" class="picking" size="small" @click="reverify">反审</el-button>
                    <el-button type="primary" class="picking" size="small" @click="audit">审核</el-button>
                    <el-button type="primary" class="picking" size="small"  @click='outage'>停用</el-button>
                    <el-button type="primary" class="picking" size="small"  @click="Enabled">启用</el-button>
                    <el-button type="primary" class="picking" size="small" @click="added">添加</el-button>
                    <div class="col-md-12 row row-table-box">
                        <div class="shopBg">
                          <label>名称：</label>
                            <el-autocomplete class="inline-input" v-model="state1"    :fetch-suggestions="querySearch" placeholder="请输入名称" size="small" :trigger-on-focus="false"   @select="handValue" >
                            </el-autocomplete>     
                            <label>手机号：</label>
                                 <el-input  class="ingred_sel on" id="telx"  v-model="telx" size="small"  placeholder="请输入完整手机号码" clearable></el-input>
                                 <el-button  class="but-left" @click="onGet" size="small" type="primary">搜索 </el-button>
                                 <el-button  class="but-left" type="primary" @click='reset' size="small" >重置</el-button>
                        </div>
                        <div class="table_margin">
                            <p style="height:20px;line-height:20px;display: inline-flex;float: right;">
                                <span class="spTip" style="background:#fff;border:1px solid #ccc"></span>未审核
                                <span class="spTip" style="background:#ccc;"></span>停用
                                <span class="spTip" style="background:#9fc53e;"></span>已审核
                            </p>
                            <el-table :data="tableData" border size="small" @select="check" style="width: 100%"  :row-class-name="tableRowClassName"  @filter-change="filterTag"  @selection-change="handleSelectionChange">
                                <el-table-column type="selection" align="center" :resizable='false' width="50"></el-table-column>
                                <el-table-column prop="loop"  align="center" label="序号"  :resizable='false' width="50"> </el-table-column>
                                <el-table-column  prop="jigou" align="center" label="所属机构" :resizable='false'  min-width="150"></el-table-column>
                                <el-table-column prop="type"  align="center" label="类型" width="80" :resizable='false' column-key="type" :filters="[{ text: '分公司', value: '1' }, { text: '代理商', value: '2' },{ text: '客户', value: '3' }]">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.type===1">分公司</span>
                                        <span v-if="scope.row.type===2">代理商</span>
                                        <span v-if="scope.row.type===3">客户</span>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="name" align="center" :resizable='false' label="名称" min-width="170"></el-table-column>
                                <el-table-column prop="tel"  align="center"   :resizable='false' label="手机号" width="110"></el-table-column>
                                <el-table-column prop="supervisor"  align="center"  :resizable='false' label="审核人" min-width="100"></el-table-column>
                                <el-table-column prop="verified_at"  align="center" :resizable='false'  label="审核时间" width="160"></el-table-column>
                                <el-table-column prop="admin_a" align="center" :resizable='false'  label="录入人" width="70"></el-table-column>
                                <el-table-column prop="created_at"  align="center" label="录入时间" :resizable='false'  width="160"></el-table-column>
                                <el-table-column prop="status_a" label="审核状态" align="center" :resizable='false'  width="90" column-key="status" :filters="[{ text: '未审核', value: '1,11' }, { text: '已审核', value: '2,12' }]">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.status_a===1">未审核</span>
                                        <span v-if="scope.row.status_a===2">已审核</span>
                                        <span v-if="scope.row.status_a===11">未审核</span>
                                        <span v-if="scope.row.status_a===12">已审核</span>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="status" label="状态" align="center" :resizable='false'  width="70" column-key="status" :filters="[{ text: '启用', value: '1,2' }, { text: '停用', value: '11,12' }]">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.status===1">启用</span>
                                        <span v-if="scope.row.status===2">启用</span>
                                        <span v-if="scope.row.status===11">停用</span>
                                        <span v-if="scope.row.status===12">停用</span>
                                    </template>
                                </el-table-column>
                                <el-table-column fixed="right" align="center" :resizable='false' label="操作" width="120">
                                    <template slot-scope="scope" >
                                        <template>
                                            <a  v-if="scope.row.status===1"  class="updata" @click="updataDis(scope)">修改</a >
                                            <a  v-if="scope.row.status===11 ||scope.row.status===12 ||scope.row.status===2"  class="updata" @click="updataDis(scope)"></a >
                                        </template>
                                            <a  class="updata"  @click="lookDis(scope)">查看</a >
                                    </template>
                                </el-table-column>
                            </el-table>
                            <div class="pagination-box">
                                <el-pagination background :page-size="10" @current-change="handleCurrentChange" layout="prev, pager, next" :total="total"></el-pagination>
                            </div>
                        </div>
                    </div>
                 
                </div>
            </div>
      </div>
  </div>
 
  <script>
      const App=new Vue({
        el: '#app',
        data() {
          return {
            state1:'',
            dialog:false,//上传对话框
            fileList:[],//点击修改显示上传默认图片
            agreement:'',//input 上传给后台的
            ImageUrl:'',//上传图片的路径
            list:'',//修改之后的上传路径 给后台的
            aelect_pid:'',
            aelect_type:'',
            pleader:'',
            options: [],
            selectedOptions:[],
            Visible: false,//查看对话框
            UpdataForm:false,//修改对话框
            title:'',//使用与停用
            changboxVal:[],//全选获得id
            tableData: [],//表单
            change:1,//分页 默认为1
            total:1,//分页总数
            checkbox:'',//表单使用跟停用点击的checkbox的id
            name:'',//查询点击名称
            tel:'',//查询点击手机号
            pidx:'',//查询点击所属机构
            ids:[],//表单反审点击的checkbox
            type:'',//table里下拉
            status:'',//table里下拉
            status_a:'',//table里下拉
            status_b:[],//table里下拉
            temp:true,//使用停用的开关
            state:'',//所属机构下拉
            resta:[],//表格里的状态
            textVal:'',//这个是机构输入的值
            kwVal:'',//这个是机构返回的值
            restaurants: [],
            data_x:[],
            ids:'',//导出装id
            itemVal:'',
                 formDalog: {
                    agreement:'',
                    id:'',//
                    parent: '',//所属机构
                    name: '',//名称
                    type: '',//类型
                    tel: '',//手机号
                    status:'',//当前状态
                    area_bh:'',//
                    address: '',//详细地址
                    loguser: '',//录入人
                    created_at: '',//录入时间
                    supervisor: '',//审核人
                    verified_at: '',//审核时间
                    discount_default: '',//默认折扣
                    policy_discount: '',//实际折扣
                    spring_rate: '',//第一季度
                    summer_rate: '',//第二季度
                    fall_rate: '',//第三季度
                    winter_rate: '',//第四季度
                    year_rate: '',//全年
                    spring_start:'',//第一季度时间
                     summer_start:'',//第二季度时间
                     fall_start:'',//第三季度时间
                     winter_start:'',//第四季度时间
                     year_start:'',//全年季度时间
                     policy_type:'1',
                     spring_end:'',//结束第一季度时间
                     summer_end:'',//结束第二季度时间
                     fall_end:'',//结束第三季度时间
                     winter_end:'',//结束第四季度时间
                     year_end:'',//结束全年季度时间
                    first_daterange:[],//
                    second_daterange:[],//
                    third_daterange:[],//
                    fourth_daterange:[],//
                    year_daterange:[],
                   },
                 area: [],//省市区
                 area_bha:"",//
                 telx:'',
                 namex:"",
                 aelect_pid:'',
                 aelect_type:'',
            }
        },
        methods: {
            querySearch(queryString, cb) {
                        let self = this
                        $.ajax({
                        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                        type: 'get',
                        dataType:'json',
                        url: '/clients/indexapi',
                        data:{
                            name:this.state1,
                            all:1
                        },
                        success:function(res){
                            if(res.result.success){
                                var results=[];
                                for(var i=0;i<res.content.data.length;i++){
                                    results.push({
                                        'value':res.content.data[i].name,
                                        'id':res.content.data[i].id
                                    })
                                }
                                clearTimeout(this.timeout);
                                this.timeout = setTimeout(() => {
                                    cb(results);
                                }, 2000 * Math.random());
                                $(".el-autocomplete-suggestion.el-popper.is-loading").show();
                            }else{
                                self.$notify.error({
                                    title: '提示',
                                    message: res.result.errorMsg,
                                });
                            }
                        }
                    })
              },
                  //下拉选择之后的值
            handValue(item) {
                this.role=item.id
            },
            handleRemove(file, fileList) {
                var replce=''
                for(var e in fileList){
                   replce=fileList[e].url
                   this.agreement=replce.replace('https://yann.52mylife.cn/upload/','')
                   this.formDalog.agreement=this.agreement
                }
             },
            handlePictureCardPreview(file) {
                this.ImageUrl = file.url;
                this.dialog = true;
            },
            hangSuccess(response, file, fileList){
              let list=''
              if(file!=''){
                  list=this.agreement+','+file.response.content 
                  if(this.agreement==null){
                    list=file.response.content  
                    this.agreement=list
                    this.formDalog.agreement=this.agreement
                  }
                   this.agreement=list
                   this.formDalog.agreement=this.agreement
               }
           },
           beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isPNG = file.type === 'image/png';
                const isPDF = file.type === 'image/pdf,';
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isJPG &&  !isPNG && !isPDF) {
                this.$notify({
                        title: '警告',
                        message: '上传图片必须是JPG/PNG/BMP/PDF 格式!',
                        type: 'warning'
                    });
                return false;
                }
                if (!isLt2M) {
                    this.$notify({
                            title: '警告',
                            message: '上传头像图片大小不能超过 2MB!',
                            type: 'warning'
                        });
                    return false;
                }
                return (isJPG || isPNG || isPDF)&& isLt2M;
            },
          typeValue(val){
            this.formDalog.type=val
          },
          obtainValue(val){
            this.formDalog.pid=val
          },
        reset(){
            this.status_a='',
            this.telx="",
            this.tel="",
            this.namex='',
            this.name='',
            this.type='',
            this.state1='',
            this.status='',
            this.setGain();
          },
          //表里的row颜色
          tableRowClassName({row}){
             if(row.status==11 || row.status==12 ){
              return 'warning-row';
             }else if(row.status==2){
              return 'success-row';
             }
             return '';
          },
           //多选框获得id
           handleSelectionChange(val){
            this.checkbox=[]
            this.changboxVal=[]
            this.resta=[]
                  for(var e in val){
                    this.changboxVal.push(val[e].id)//审核与反审
                    this.resta.push(val[e].status)//表里的状态
                  }
            },
          //修改的三级联动
          handleChange(value) {
            const that=this;
                $.ajax({
                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                  type:'get',
                  url:'/clients/address'
                }).then(function(response){
                  let data=response
                  const options = [];
                  for (let item in data) {
                    let province = {
                            value: data[item].value,
                            label: data[item].label,
                            children: []
                        };
                        for (let city in data[item].children) {
                           let counties=[];
                          for (let county in data[item].children[city].children) {
                                let cityno=data[item].children[city].children[county];
                                counties.push({value:cityno.value,label:cityno.label});
                            }
                            province.children.push({
                                value: data[item].children[city].value,
                                label: data[item].children[city].label,
                                children:counties
                            });
                        }
                            options.push(province)
                      }
                      that.$data.options=options;
                    })
              },
          //修改的提交
          UpdataSubmit() {
             let that=this
             let arr=that.area
                  if(arr.length == 0){
                      that.formDalog.area_bh=that.area_bha
                   $.ajax({
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                      type:"put",
                      url:`/clients/update/${this.formDalog.id}`,
                      data:this.formDalog
                    }).then(function(res){
                       that.setGain();  
                       that.UpdataForm=false
                   })
                  }else{
                    that.formDalog.area_bh=arr[2]
                          $.ajax({
                            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                            type:"put",
                            url:`/clients/update/${this.formDalog.id}`,
                            data:this.formDalog
                        }).then(function(res){
                            that.setGain();  
                            that.UpdataForm=false
                        })
                  }
          },  
          //查看对话框
          handleClose(done) {
                  this.Visible=false
                  this.aelect_pid=''
                  this.aelect_type=''
                  this.formDalog.name=''
                  this.formDalog.id=''
                  this.formDalog.tel=''
                  this.formDalog.status=''
                  this.pleader=''
                  this.formDalog.address=''
                  this.formDalog.discount_default=''    
                  this.UpdataForm=false
            },
            //机构下拉框选好之后
            handleSelect(item){
            this.itemVal=item
            },
            //新增跳转
            added(){
                window.location.href = "/clients/create";
            },
             // 审核
                audit(){
                let self = this
                    if(this.changboxVal==''){
                            this.$notify.error({
                                title: '提示',
                                message: '请先选择需要审核的项',
                            });
                        return false;
                        }
                        if(this.changboxVal.length==1){ 
                            if(this.resta==1 || this.resta==11){
                            $.ajax({
                                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                                type:'post',
                                url:'/clients/verify',
                                data:{
                                    ids:this.changboxVal
                                },
                                success:function(res){
                                    if(res.result.success==true){
                                        self.setGain();
                                            self.$notify.success({
                                                title: '提示',
                                                message: '审核提交成功',
                                            });
                                    }else{
                                        self.$notify.error({
                                            title: '错误',
                                            message:res.result.errorMsg
                                            });
                                       }
                                    }
                                })
                            }else{
                              this.$notify({
                                    title: '警告',
                                    message: '此项已审核',
                                    type: 'warning'
                                });
                            }
                        }else{
                            for(var e in this.resta){
                                if(this.resta[e]==2 || this.resta[e]==12){
                                this.$notify({
                                        title: '警告',
                                        message: '你选的项中有已审核的项 已审核的项不能再审核',
                                        type: 'warning'
                                    });
                                    return false; 
                                }
                            }
                            for(var k in this.resta){
                                if(this.resta[k]==1){
                                    this.resta==2
                                    this.shenHer();
                                    this.setGain();
                                }
                                if(this.resta[k]==11){
                                    this.resta==12
                                    this.shenHer();
                                    this.setGain();
                                }
                                this.$notify.success({
                                        title: '提示',
                                        message: '审核提交成功',
                                    });
                                break;
                            }
                      }
                },
         //反审
         reverify(){
          let self = this
              if(this.changboxVal==''){
                    this.$notify.error({
                        title: '提示',
                        message: '请先选择需要反审的项',
                    });
                    return false;
                }
                if(this.changboxVal.length==1){ 
                    if(this.resta==2 || this.resta==12){
                      $.ajax({
                        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                          type:'post',
                          url:'/clients/verify',
                          data:{
                            ids:this.changboxVal
                          },
                          success:function(res){
                              if(res.result.success==true){
                                  self.setGain();
                                    self.$notify.success({
                                        title: '提示',
                                        message: '反审提交成功',
                                    });
                             }else{
                                self.$notify.error({
                                    title: '错误',
                                    message:res.result.errorMsg
                                    })
                                }
                            }
                          })
                    }else{
                      this.$notify({
                          title: '警告',
                          message: '此项未审核，不能进行反审',
                          type: 'warning'
                       });
                    }
                }else{
                    for(var e in this.resta){
                        if(this.resta[e]==1 || this.resta[e]==11){
                        this.$notify({
                                title: '警告',
                                message: '你选的项中有未审核的项 未审核的项不能再反审',
                                type: 'warning'
                              });
                              return false; 
                         }
                    }
                    for(var k in this.resta){
                         if(this.resta[k]==2){
                            this.resta==1
                            this.shenHer();
                            this.setGain();
                         }
                         if(this.resta[k]==12){
                            this.resta==11
                            this.shenHer();
                            this.setGain();
                         }
                      break;
                    }
                }
         },
         //导出
         expost(){
            if(this.changboxVal!=''){
              window.location.href=`/clients/export?ids=${this.changboxVal}`
            }else{
              this.$notify.error({
                    title: '提示',
                    message: '请选择需要导出的项',
                });
            }
         },
         //使用
         Enabled(){
             let that=this
                if(this.changboxVal==''){
                    this.$notify.error({
                            title: '提示',
                            message: '请选择你要操作的项',
                        });
                        return false;
                }
                  if(this.resta==1 || this.resta==2){
                    this.$notify.error({
                        title: '提示',
                        message: '使用状态下 不能重复操作',
                    });
                    return false;
                  }
                  if(this.changboxVal.length==1){
                    if(this.resta==11){
                        this.resta=1
                        this.Activepost();
                        this.setGain();
                      
                        that.$notify.success({
                            title: '提示',
                            message: '提交成功',
                        });

                     }
                     if(this.resta==12){
                        this.resta=2
                        this.Activepost();
                        this.setGain();
                        that.$notify.success({
                            title: '提示',
                            message: '提交成功',
                        });
                     }
                  }else{
                    for(var e in this.resta){
                         if(this.resta[e]==1 || this.resta[e]==2){
                            this.$notify.error({
                                title: '提示',
                                message: '使用状态下 不能重复操作',
                            });
                            return false;
                         }
                     }
                     for(var e in this.resta){
                         if(this.resta[e]==11){
                            this.resta=1
                            this.Activepost();
                            this.setGain();
                            that.$notify.success({
                                title: '提示',
                                message: '提交成功',
                            });
                         }
                         if(this.resta[e]==12){
                            this.resta=2
                            this.Activepost();
                            this.setGain();
                            that.$notify.success({
                                title: '提示',
                                message: '提交成功',
                            });
                         }
                     break;
                     }              
                  }
            },
         //停用
         outage(){
            let that=this
            if(this.changboxVal==''){
                this.$notify.error({
                        title: '提示',
                        message: '请选择你要操作的项',
                    });
                    return false;
                   }
                  if(this.resta==11 || this.resta==12){
                    this.$notify.error({
                        title: '提示',
                        message: '停用状态下 不能重复操作',
                    });
                    return false;
                  }
                  if(this.changboxVal.length==1){
                    if(this.resta==1){
                        this.resta=11
                        this.Activepost();
                        this.setGain();
                        that.$notify.success({
                                title: '提示',
                                message: '提交成功',
                            });
                     }
                     if(this.resta==2){
                        this.resta=12
                        this.Activepost();
                        this.setGain();
                        that.$notify.success({
                                title: '提示',
                                message: '提交成功',
                            });
                     }
                  }else{
                    for(var e in this.resta){
                         if(this.resta[e]==11 || this.resta[e]==12){
                            this.$notify.error({
                                title: '提示',
                                message: '停用状态下 不能重复操作',
                            });
                            return false;
                         }
                     }
                     for(var e in this.resta){
                         if(this.resta[e]==1){
                            this.resta=11
                            this.Activepost();
                            this.setGain();
                            that.$notify.success({
                                title: '提示',
                                message: '提交成功',
                            });
                         }
                         if(this.resta[e]==2){
                            this.resta=12
                            this.Activepost();
                            this.setGain();
                            that.$notify.success({
                                title: '提示',
                                message: '提交成功',
                            });
                         }
                      break;
                     }
                  }
           },
         check(selection, row){//多选框 
               this.changbox=[]
               this.checkbox=row.id
             },
         //点击查询
         onGet(){
           var that=this
           this.name=$('#namex').val();
           this.tel=$('#telx').val();
           let i=0
              let self = this
              let skip=self.change
              let parents = []
              var pat=[]
            $.ajax({
                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
              type:'get',
              url:'/clients/indexapi',
              dataType:'json',
              data:{
                name:this.state1,
                tel:this.tel,
                'parent.name':this.pidx
              },
              success:function(res){
                if(res.content.data!=null){
                 res.content.current_page =skip  
                 self.total=res.content.total
                      var opt=[];
                      let i = -10;
                      for(var e of res.content.data){
                        i++;
                        if(e.parent==null){
                           e.parent='为空'
                          }
                       if(e.verify_user==null){
                           e.verify_user='为空'
                          }
                        opt.push({
                          'loop':i+(10*self.change), 
                          'jigou':e.parent.company_name,
                          'type':e.type,
                          'name':e.name,
                          'tel':e.tel,
                          'supervisor':e.supervisor,
                          'supervisor':e.verify_user.admin_name,
                          'verified_at':e.verified_at,
                          'admin_a':e.log_user.admin_name,
                          'created_at':e.created_at,
                          'status':e.status,
                          'id':e.id,
                          'status_a':e.status
                        }) 
                   }
                  self.tableData=opt;
                }else{
                    self.$notify.error({
                            title: '提示',
                            message: '未找到你要搜索的内容',
                        });
                     return false;
                  }
               }
            })
          },
          //列表里的下拉菜单
          filterTag(value) {
             if(value.type!=undefined){
                 var val1=value.type;
                 var stas1='';
                for(let i=0; i<val1.length;i++){
                    stas1=stas1+val1[i]+',';
                } 
                this.type=stas1.substr(0, stas1.length - 1);
                this.start(); 
             }
             if(value.status!=undefined){
                 var val2=value.status;
                 var stas2='';
                for(let i=0; i<val2.length;i++){
                    stas2=stas2+val2[i]+',';
                } 
                this.status=stas2.substr(0, stas2.length - 1);
                this.start(); 
              }
             if(value.status_a!=undefined){
                 var val2=value.status_a;
                 var stas2='';
                for(let i=0; i<val2.length;i++){
                    stas2=stas2+val2[i]+',';
                } 
                this.status_a=stas2.substr(0, stas2.length - 1);
                this.start(); 
              }
              if(value.status_b!=undefined){
                 var val2=value.status_b;
                 var stas2='';
                for(let i=0; i<val2.length;i++){
                    stas2=stas2+val2[i]+',';
                } 
                this.status_b=stas2.substr(0, stas2.length - 1);
                this.start(); 
              }
            },
         start(){ 
           let i=0
              let self = this
              let skip=self.change
              let parents = []
              var pat=[]
            $.ajax({
                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                type:'get',
                url:'/clients/indexapi',
                dataType:'json',
                data:{
                name:this.name,
                tel:this.tel,
                type:this.type,
                status:this.status,
                status_a:this.status_a,
                status_b:this.status_b,
                'parent.name':this.pidx
              },
              success:function(res){
                 res.content.current_page =skip  
                 self.total=res.content.total
                      var opt=[];
                      let i = -10;
                      for(var e of res.content.data){
                        i++;
                        if(e.parent==null){
                           e.parent='为空'
                          }
                       if(e.verify_user==null){
                           e.verify_user='为空'
                          }
                        opt.push({
                          'loop':i+(10*self.change), 
                          'jigou':e.parent.company_name,
                          'type':e.type,
                          'name':e.name,
                          'tel':e.tel,
                          'supervisor':e.supervisor,
                          'supervisor':e.verify_user.admin_name,
                          'verified_at':e.verified_at,
                          'admin_a':e.log_user.admin_name,
                          'created_at':e.created_at,
                          'status':e.status,
                          'id':e.id,
                          'status_a':e.status
                        })  
                   }
                   self.tableData=opt;
                }
              })
            },
          handleCurrentChange(val){
               this.change=val
               this.setGain();    
          },
          //获取table数据
         setGain(){
           let i=0
              let self = this
              let skip=self.change
              let parents = []
              var pat=[]
            $.ajax({
                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
              type:'get',
              url:'/clients/indexapi',
              dataType:'json',
              data:{
                current_page:this.change,
                name:this.name,
                tel:this.tel,
                type:this.type,
                status:this.status,
                'parent.name':this.pidx
              },
              success:function(res){
                 res.content.current_page =skip  
                 self.total=res.content.total
                      var opt=[];
                      let i = -10;
                      for(var e of res.content.data){
                        i++;
                        if(e.parent==null){
                           e.parent='为空'
                          }
                       if(e.verify_user==null){
                           e.verify_user='为空'
                          }
                        opt.push({
                          'loop':i+(10*self.change), 
                          'jigou':e.parent.company_name,
                          'type':e.type,
                          'name':e.name,
                          'tel':e.tel,
                          'supervisor':e.supervisor,
                          'supervisor':e.verify_user.admin_name,
                          'verified_at':e.verified_at,
                          'admin_a':e.log_user.admin_name,
                          'created_at':e.created_at,
                          'status':e.status,
                          'id':e.id,
                          'status_a':e.status
                        })
                  }
                  self.tableData=opt;
               }
            })
          },
           Activepost(){//使用跟停用按钮用的
            let self = this
                  $.ajax({
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                        type:'post',
                        url:'/clients/active',
                        dataType:'json',
                        data:{
                          ids:this.changboxVal
                        },
                        success:function(res){
                            if(res.result.success==true){
                                 self.setGain();
                            }else{
                                self.$notify.error({
                                    title: '错误',
                                    message: res.result.errorMsg
                                });
                             }
                        }
                    })
               },
             shenHer(){//使用跟停用按钮用的
                 let self = this
                 $.ajax({
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                    type:'post',
                    url:'/clients/verify',
                    data:{
                        ids:this.changboxVal
                    },
                    success:function(res){
                        if(res.result.success==true){
                             self.setGain();
                        }else{
                            self.$notify.error({
                                    title: '错误',
                                    message: res.result.errorMsg
                                });
                            }
                        }
                    })
               },
            areabh(){
               let that=this
                  $.ajax({
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                  type:'get',
                  url:'/clients/children/',
                  dataType:'json',
                  success:function(res){
                      if(res.result.success==true){
                          that.data_x=res.content
                      }else{
                        self.$notify.error({
                                title: '错误',
                                message: res.result.errorMsg
                            });
                         }
                     }
                })
             },
          //查看
           lookDis(scope){
                window.location.href=`/clients/look?id=${scope.row.id}`
                let that=this
                that.fileList=[]
                that.agreement=[]
                $.ajax({
                    headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                          type:'get',
                          url:`/clients/show/${scope.row.id}`,
                          dataType:'json',
                           success:function(res){
                            if(res.content.files!=''){
                                for(var e in res.content.files){
                                that.fileList.push({
                                    url:res.content.files[e]
                                  })
                                }
                            }
                            that.agreement=res.content.agreement
                            that.formDalog.agreement=res.content.agreement
                            that.area_bha=res.content.area_bh
                            that.aelect_pid=res.content.parent.company_name
                            that.aelect_type=res.content.type
                            that.formDalog.pid=res.content.pid
                            that.formDalog.type=scope.row.type
                            that.formDalog.name=res.content.name
                            that.formDalog.id=scope.row.id
                            that.formDalog.tel=res.content.tel
                            that.formDalog.status=res.content.status
                            that.pleader=res.content.province+'/'+res.content.city+'/'+res.content.district
                            that.formDalog.address=res.content.address
                            that.formDalog.discount_default=res.content.discount_default
                           for(var e in res.content.policies){
                            that.formDalog.policy_discount=res.content.policies[e].policy_discount
                            that.formDalog.spring_rate=res.content.policies[e].spring_rate
                            that.formDalog.spring_start=res.content.policies[e].spring_start
                            that.formDalog.spring_end=res.content.policies[e].spring_end
                            that.formDalog.summer_rate=res.content.policies[e].summer_rate
                            that.formDalog.summer_start=res.content.policies[e].summer_start
                            that.formDalog.summer_end=res.content.policies[e].summer_end
                            that.formDalog.fall_rate=res.content.policies[e].fall_rate
                            that.formDalog.fall_start=res.content.policies[e].fall_start
                            that.formDalog.fall_end=res.content.policies[e].fall_end
                            that.formDalog.winter_rate=res.content.policies[e].winter_rate
                            that.formDalog.winter_start=res.content.policies[e].winter_start
                            that.formDalog.winter_end=res.content.policies[e].winter_end
                            that.formDalog.year_rate=res.content.policies[e].year_rate
                            that.formDalog.year_start=res.content.policies[e].year_start
                            that.formDalog.year_end=res.content.policies[e].year_end
                           }
                        }
                   })
               },
               //点击修改
               updataDis(scope){
                    window.location.href=`/clients/change?id=${scope.row.id}`
                    let that=this
                    that.areabh();
                    that.fileList=[]
                    that.agreement=[]
                    $.ajax({
                       headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                          type:'get',
                          url:`/clients/edit/${scope.row.id}`,
                          dataType:'json',
                          success:function(res){
                            if(res.content.files!=''){
                                for(var e in res.content.files){
                                that.fileList.push({
                                    url:res.content.files[e]
                                    })
                                }
                            }
                            that.agreement=res.content.agreement
                            that.formDalog.agreement=res.content.agreement
                            that.area_bha=res.content.area_bh
                            that.aelect_pid=res.content.parent.company_name
                            that.aelect_type=res.content.type
                            that.formDalog.pid=res.content.pid
                            that.formDalog.type=scope.row.type
                            that.formDalog.name=res.content.name
                            that.formDalog.id=scope.row.id
                            that.formDalog.tel=res.content.tel
                            that.formDalog.status=res.content.status
                            that.pleader=res.content.province+'/'+res.content.city+'/'+res.content.district
                            that.formDalog.address=res.content.address
                            that.formDalog.discount_default=res.content.discount_default
                        for(var e in res.content.policies){
                           that.formDalog.policy_discount=res.content.policies[e].policy_discount
                           that.formDalog.spring_rate=res.content.policies[e].spring_rate
                           that.formDalog.spring_start=res.content.policies[e].spring_start
                           that.formDalog.spring_end=res.content.policies[e].spring_end
                           that.formDalog.summer_rate=res.content.policies[e].summer_rate
                           that.formDalog.summer_start=res.content.policies[e].summer_start
                           that.formDalog.summer_end=res.content.policies[e].summer_end
                           that.formDalog.fall_rate=res.content.policies[e].fall_rate
                           that.formDalog.fall_start=res.content.policies[e].fall_start
                           that.formDalog.fall_end=res.content.policies[e].fall_end
                           that.formDalog.winter_rate=res.content.policies[e].winter_rate
                           that.formDalog.winter_start=res.content.policies[e].winter_start
                           that.formDalog.winter_end=res.content.policies[e].winter_end
                           that.formDalog.year_rate=res.content.policies[e].year_rate
                           that.formDalog.year_start=res.content.policies[e].year_start
                           that.formDalog.year_end=res.content.policies[e].year_end
                          }
                        }
                    })
                }   
           },
          mounted() {
               this.setGain();
          },
      })
  </script>
@endsection